package com.ruoyi.psi.quality.item.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.psi.quality.item.domain.InspectItem;
import com.ruoyi.psi.quality.item.service.IInspectItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 质检项目
 * @author Drj 2021/6/28
 */
@RestController
@RequestMapping("/psi/quality/item")
@Api(value = "质检项目模块", tags = "质检项目接口")
public class InspectItemController extends BaseController {
    @Autowired
    private IInspectItemService inspectItemService;


    /**
     * 获取质检项目列表
     * @param inspectItem
     * @return
     */
    @ApiOperationSupport(includeParameters = {"InspectItem.inspectItemId", "InspectItem.inspectItemName"})
    @ApiOperation(value = "获取质检项目列表",notes = "查询所有质检项目信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody InspectItem inspectItem){
        startPage();
        List<InspectItem> inspectItemList = inspectItemService.selectInspectItemList(inspectItem);
        return getDataTable(inspectItemList);
    }

    /**
     * 导出质检项目
     * @param inspectItem
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody InspectItem inspectItem)
    {
        List<InspectItem> list = inspectItemService.selectInspectItemList(inspectItem);
        ExcelUtil<InspectItem> util = new ExcelUtil<InspectItem>(InspectItem.class);
        return util.exportExcel(list, "质检项目数据");
    }

    /**
     * 新增质检项目
     * @param inspectItem
     * @return
     */
    @ApiOperation(value = "新增质检项目", notes = "新增质检项目")
    @ApiImplicitParam(name = "inspectItem", value = "新增质检项目", dataType = "InspectItem")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody InspectItem inspectItem){

        try {
            return toAjax(inspectItemService.insertInspectItem(inspectItem));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("新增失败");
        }
    }

    /**
     * 修改质检项目
     * @param inspectItem
     * @return
     */
    @ApiOperation(value = "修改质检项目", notes = "修改质检项目")
    @ApiImplicitParam(name = "inspectItem", value = "修改质检项目", dataType = "InspectItem")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody InspectItem inspectItem)
    {
        return toAjax(inspectItemService.updateInspectItem(inspectItem));
    }

    /**
     * 删除质检项目
     * 仅修改删除标志位
     * @param inspectItem
     * @return
     */
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody InspectItem inspectItem)
    {

        return toAjax(inspectItemService.updateInspectItemDeleteFlag(inspectItem));
    }
}
